/**
 * Copyright  2016
 *
 * 	All right reserved.
 *
 *	Created on  2016年3月8日 下午3:57:30
 * 
 */
package com.hongxinguoji.manager.company.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongxinguoji.manager.common.util.EasyUIDataGridResult;
import com.hongxinguoji.manager.company.mapper.HxCompanyMapper;
import com.hongxinguoji.manager.company.pojo.HxCompany;
import com.hongxinguoji.manager.company.pojo.HxCompanyExample;
import com.hongxinguoji.manager.company.service.ICompanySerrvice;

/**
 * 
 * @author jing
 *
 */
@Service
public class CompanyServiceImpl implements ICompanySerrvice {

	@Resource
	private HxCompanyMapper companyMapper;

	@Override
	public EasyUIDataGridResult getCompanyList(Integer page, Integer rows) {
		EasyUIDataGridResult result = new EasyUIDataGridResult();
		// 分页处理
		PageHelper.startPage(page, rows);
		HxCompanyExample example = new HxCompanyExample();
		List<HxCompany> list = companyMapper.selectByExample(example);
		PageInfo<HxCompany> pageInfo = new PageInfo<>(list);
		result.setTotal(pageInfo.getTotal());
		result.setRows(list);
		return result;
	}

	@Override
	public void addCompany(HxCompany company) {
		companyMapper.insert(company);
	}

	@Override
	public void updateCompany(HxCompany company) {
		Long id = company.getId();
		HxCompany hxCompany = companyMapper.selectByPrimaryKey(id);

		hxCompany.setAbout(company.getAbout());
		hxCompany.setAdvertiseEmail(company.getAdvertiseEmail());
		hxCompany.setCopyright(company.getCopyright());
		hxCompany.setGroupAddress(company.getGroupAddress());
		hxCompany.setGroupServiceTel(company.getGroupServiceTel());
		hxCompany.setGroupTel(company.getGroupTel());
		hxCompany.setName(company.getName());
		hxCompany.setRecord(company.getRecord());

		companyMapper.updateByPrimaryKey(hxCompany);

	}

	@Override
	public void deleteCompany(Long id) {
		companyMapper.deleteByPrimaryKey(id);
	}

}
